package com.taikang.hmp.hbusiness.doctor.information.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.service.impl.BaseServiceImpl;
import com.taikang.hmp.frame.customer.bean.CustomerInfo;
import com.taikang.hmp.hbusiness.diabetes.measure.medicine.bean.Medplan;
import com.taikang.hmp.hbusiness.diabetes.measure.medicine.bean.Medplandetail;
import com.taikang.hmp.hbusiness.doctor.information.bean.Information;
import com.taikang.hmp.hbusiness.doctor.information.service.InformationService;

public class InformationServiceImpl  extends BaseServiceImpl implements InformationService{

	@Override
	public List<Dto> getInformationList() {
		List<Information> resultList = super.getNewDao().queryForList("message_space.getInformationList");
//		System.out.println(resultList.size()+"0000000000000000000000000000000000000000000");
		List<Dto> result = new ArrayList<Dto>();
		for (int i = 0; resultList!=null && i < resultList.size(); i++) {
			Information medtemp = resultList.get(i);
			Dto resultMap = new BaseDto();
			resultMap.put("information_id", medtemp.getInformation_id());
			resultMap.put("title", medtemp.getTitle());
			resultMap.put("type", medtemp.getType());
			resultMap.put("image_url", medtemp.getImage_url());
			resultMap.put("dates", medtemp.getDates());
			resultMap.put("summary", medtemp.getSummary());
			resultMap.put("content", medtemp.getContent());
			resultMap.put("review_status", medtemp.getReview_status());
			resultMap.put("audit_result", medtemp.getAudit_result());
			resultMap.put("readcount", medtemp.getReadcount());
			resultMap.put("source_cd", medtemp.getSource_cd());
			resultMap.put("operater", medtemp.getOperater());
			resultMap.put("operate_date", medtemp.getOperate_date());
			
			

			result.add(resultMap);
		}
		return result;
	}

	@Override
	public void saveInformation(Dto dto) {
		// TODO Auto-generated method stub
		
		
		String information_id=dto.getAsString("information_id");
		String title=dto.getAsString("title");
		String type=dto.getAsString("type");
		String dates=dto.getAsString("dates");
		String summary=dto.getAsString("summary");
		String image_url=dto.getAsString("image_url");
		String content=dto.getAsString("content");
		String review_status=dto.getAsString("review_status");
		String audit_result=dto.getAsString("audit_result");
		String readcount=dto.getAsString("readcount");
		String source_cd=dto.getAsString("source_cd");
		String operater=dto.getAsString("operater");
		
		
	
		
	
		Date operate_date = new Date(); 
		Information medplan = new Information();
		medplan.setOperater(dto.getAsString("uid"));
		medplan.setOperate_date( operate_date );
		medplan.setSource_cd(dto.getAsString("requestsource"));
	    medplan.setContent(content);
	    medplan.setAudit_result(audit_result);
	    medplan.setDates(dates);
	    medplan.setImage_url(image_url);
	    medplan.setReadcount(readcount);
	    medplan.setReview_status(review_status);
	    medplan.setSummary(summary);
	    medplan.setTitle(title);
	    medplan.setOperater(operater);
	    medplan.setType(type);
	    
	   

		//保存用药计划, 保证唯一：customer_id date medtimespan_cd
		String plan_id = null;
		Information existMedplan = (Information)super.getNewDao().queryForObject("message_space.getInformationByOne", medplan);
		if (existMedplan!=null) {
			plan_id = existMedplan.getInformation_id();
			super.getNewDao().update("message_space.updateInformation", medplan);
		} else {
		    information_id = java.util.UUID.randomUUID().toString();
			medplan.setInformation_id(information_id);
			super.getNewDao().insert("message_space.insert_Information", medplan);
		}

		
	}

	@Override
	public void delInformationList(Dto paramDto) {
		// TODO Auto-generated method stub
		
		List<Information> customerIdList = super.getNewDao().queryForList("message_space.getInformationByOne", paramDto.getAsString("uid"));
		String information_id = customerIdList.get(0).getInformation_id();
		Map<String,String> map = new HashMap<String,String>();
		
		map.put("information_id", information_id);
		super.getNewDao().delete("message_space.delInformationone", map);
	}

	

}
